// 发送请求
import { allArticle } from "@/api";

// 常量
const ALL = "all_article";

const actions = {
	async [ALL]({ commit }) {
		let result = await allArticle();
		if (result.code === 200) {
			commit(ALL, result.data);
			return Promise.resolve("ok");
		} else {
			return Promise.reject(new Error("获取全部文章数据失败！"));
		}
	},
};

const mutations = {
	[ALL](state, value) {
		state[ALL] = value;
	},
};

const state = {
	[ALL]: [],
};

export default {
	//开启命名空间,这个必须要开，不然报错
	namespaced: true,
	actions,
	mutations,
	state,
};
